﻿using ASmile.Extend;
using ASmile.Win;

namespace ASmile.Setter.DaBLL
{
    class LoginBLL
    {
        public ApiResult Login(string loginName,string loginPwd)
        {
            if (loginName.IsEmpty())
            {
                loginName = Config.Settings.DefLoginName;
            }
            if (loginPwd.IsEmpty())
            {
                loginPwd = Config.Settings.DefLoginPwd;                
            }

            var ret =
            ComData.M.LoginVerify(new ASmile.Com.Com.ArgLoginVerify
            {
                LoginName = loginName,
                LoginPwd = loginPwd,
                RoleId = Config.Settings.DefRoleId,
                ClentId = Config.Settings.ClientId
            });

            if (!ret)
            {
                return ApiResult.RetErr(ret.msg);
            }
            var user = ret.data.UserInfo;
            LoginUser.ResetLoginUser();            
            LoginUser.UserId = user.UserId;
            LoginUser.UserName = user.UserName;
            LoginUser.RoleId = user.RoleId;
            LoginUser.RoleName = user.RoleName;
            LoginUser.IsManager = user.IsManager;
            LoginUser.DeptId = user.DeptId;
            LoginUser.DeptName = user.DeptName;

            return ApiResult.RetOK(ret.msg);
        }
    }
}
